/*
 * @Author: Guiter 1336263157@qq.com
 * @Date: 2023-11-28 12:09:42
 * @LastEditors: Guiter 1336263157@qq.com
 * @LastEditTime: 2023-11-28 18:06:48
 * @FilePath: \nuxt3-music-player\src\utils\getAllInfo.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import getNowFormatDate from './times';
import { getUserPlaylist, getUserSubcount, getUseraccount } from '~/server/api/user';

/**
 * 获取用户的所有信息
 * 个人资料
 * 歌单信息
 * 歌单数量等
 */
async function getAllInfo(): Promise<void> {
  const userStore = useUserStore();
  const songsStore = useSongsStore();

  /* 获取今天的时间 */
  const days = getNowFormatDate();
  /* 存储时间 */
  userStore.setDays(days);

  /* 获取个人资料 */
  const res = await getUseraccount();
  userStore.setUserInfo(res);
  /* 获取用户的歌单信息 */
  const data = await getUserPlaylist(res.userId);
  songsStore.setSongsList(data.playlist);
  /* 获取歌单数量等信息 */
  const songsData = await getUserSubcount();
  songsStore.setSongs(songsData);
}

export default getAllInfo;
